<!DOCTYPE html>
<html class="bg-white" xmlns:th="http://www.thymeleaf.org">
<head th:include="include :: header"></head>
<link rel="stylesheet" th:href="@{/css/admin.css}" media="all" />
<body>
<form  id="dictTypeForm" lay-filter="dictTypeForm" class="layui-form model-form">
    <input type="hidden" value="" id="dictId" name="dictId">
    <div class="layui-form-item">
        <label class="layui-form-label">字典名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" id="dictName" name="dictName" lay-verify="required" placeholder="请输入字典名称">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">字典类型</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" id="dictType" name="dictType" lay-verify="required" placeholder="请输入字典类型">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" id="remark" name="remark" lay-verify="required" placeholder="请输入备注">
        </div>
    </div>
            <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="addDictType" lay-submit>保存</button>
    </div>
</form>
<!-- js部分 -->
<div th:include="include::footer"></div>
<script type="text/javascript" th:src="@{/js/common.js}"></script>
<script>
    layui.use(['layer', 'form','admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var prefix = "system/dict";

        var url = ctx+prefix+"/add";
        // 回显数据
        var post = admin.getTempData('t_DictType');
        if(post){
            form.val('dictTypeForm', post);
            url = ctx+prefix+"/edit";
        }


        // 表单提交事件
        form.on('submit(addDictType)', function (data) {
            layer.load(2);
            console.log(url);
            $.post(url, data.field, function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    top.layer.msg(data.msg, {icon: 1});
                    admin.putTempData('formOk', true);  // 操作成功刷新表格
                    // 关闭当前iframe弹出层
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                } else {
                    top.layer.msg(data.msg, {icon: 2});
                }
            });
            return false;
        });
    });
</script>
</body>
</html>